import { ApiProperty } from '@nestjs/swagger'
import { IsNumberString, IsOptional } from 'class-validator'

export abstract class BaseDto {
  @ApiProperty({ type: Number, example: 200 })
  code: number

  @ApiProperty({ type: String, example: '获取成功' })
  message: string

  @ApiProperty({ example: true, description: '请求是否成功' })
  success: boolean
}

export abstract class DefaultBaseDto extends BaseDto {
  @ApiProperty({ example: null })
  data: unknown
}

abstract class ErrorDto {
  @ApiProperty({ type: String, example: '' })
  url: string

  @ApiProperty({ type: String, example: 'POST | GET | PUT' })
  method: string

  @ApiProperty({ type: String, example: '1676196808151' })
  timestamp: string

  @ApiProperty({ example: {} })
  body: {}

  @ApiProperty({ example: {} })
  query: {}

  @ApiProperty({ example: {} })
  params: {}
}

export abstract class BaseErrorDto extends BaseDto {
  @ApiProperty({ type: Number, example: 400 })
  code: number

  @ApiProperty({ type: String, example: '获取失败' })
  message: string

  @ApiProperty({ type: Boolean, example: false })
  success: boolean

  @ApiProperty({ type: type => ErrorDto })
  request: ErrorDto
}

export class QueryPage {
  @ApiProperty({ example: '1', description: '第几页', required: false })
  @IsOptional()
  @IsNumberString({}, { message: 'pageSize 参数不合法' })
  pageIndex: string

  @ApiProperty({ example: '3', description: '每页数量', required: false })
  @IsOptional()
  @IsNumberString({}, { message: 'pageIndex 参数不合法' })
  pageSize: string
}
